package demo.mapper;

import demo.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {

    @Select("select * from UserInfo")
    List<UserInfo> queryUserInfo();

    @Select("select * from userinfo where id = #{id}")
    UserInfo queryUserInfoById1( Integer id);

    @Select("select * from userinfo order by id ${order} ")
    List<UserInfo> queryUserInfoByOrder( String order);

    @Select("select * from userinfo where id = #{value}")
    UserInfo queryUserInfoById2(@Param("value") Integer id);

    @Select("select * from userinfo where id=#{id} and username=#{userName}")
    UserInfo queryUserInfos1(Integer id,String userName);

    @Select("select * from userinfo where id=#{value} and username=#{name}")
    UserInfo queryUserInfos2(@Param("value")Integer id,@Param("name") String username);

    @Insert("insert into userinfo (username,password,age,gender,phone)" +
            " values (#{username},#{password},#{age}," +
            "#{gender},#{phone})")
    Integer insertUserInfo(UserInfo userInfo);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into userinfo (username,password,age,gender,phone)" +
            " values (#{userInfo.username},#{userInfo.password},#{userInfo.age}," +
            "#{userInfo.gender},#{userInfo.phone})")
    Integer insertUserInfo2(@Param("userInfo") UserInfo userInfo);

    @Delete("delete from userinfo where id=#{id}")
    Integer deleteUserInfo(Integer id);

    @Update("update userinfo set phone = #{phone}where id=#{id}")
    void updateUserInfo(UserInfo userInfo);

    @Select("select id,username,password,age,gender,phone,delete_flag as deleteFlag" +
            ",create_time as createTime,update_time as updateTime from UserInfo")
    List<UserInfo> queryUserInfos();

   @Results(id = "base",value = {
           @Result(column = "delete_flag",property = "deleteFlag"),
           @Result(column = "create_time",property = "createTime"),
           @Result(column = "update_time",property = "updateTime"),
   })
    @Select("select * from UserInfo")
    List<UserInfo> queryUserInfos222();

   @ResultMap("base")
   @Select("select * from userinfo")
   List<UserInfo> queryUserInfos333();

   @Select("select * from userinfo where username like concat('%',#{key},'%') ")
   List<UserInfo> queryUserInfoBylike(String key);

}
